﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/// <summary>
/// 消息的分发和调度
/// </summary>
class EventDispatcher
{
    //public static event System.Action<string> MessageHendler;
    public static event System.Action<Data.Chat> MessageHendler;
    public static event System.Action<Data.ReqRegister> RegisterHendler;
    public static event System.Action<Data.ReqLogin> LoginHendler;
    public static event System.Action<Data.ReqLogin> OtherLoginHendler;
    public static event System.Action<Data.ReqLogin> OtherHendler;



    public static void OnEvent(ByteBuffer buffer)
    {
        Protocal type = (Protocal)buffer.ReadByte();
        UnityEngine.Debug.Log("OnEvent:" + type);
        switch (type)
        {
            case Protocal.Login_CMD:
                {
                    Data.ReqLogin resp = ProtoHelper.Deserialize<Data.ReqLogin>(buffer.ReadBytes());
                    LoginHendler(resp);
                }

                break;

            case Protocal.OtherLogin_CMD:
                {
                    Data.ReqLogin resp = ProtoHelper.Deserialize<Data.ReqLogin>(buffer.ReadBytes());
                    OtherLoginHendler(resp);
                }

                break;

            case Protocal.Register_CMD:

                Data.ReqRegister req = ProtoHelper.Deserialize<Data.ReqRegister>(buffer.ReadBytes());
                RegisterHendler(req);

                break;

            case Protocal.Chat_CMD:

                string message = buffer.ReadString();
                Data.Chat chat = ProtoHelper.Deserialize<Data.Chat>(buffer.ReadBytes());
                MessageHendler(chat);

                break;
            default:
                break;
        }
    }
}
